Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Unhandled (in react-apollo) - NOT A NETWORK ERROR #1003

Closed
quadsurf opened this issue Aug 21, 2017 · 12 comments
Closed

Unhandled (in react-apollo) - NOT A NETWORK ERROR #1003

quadsurf opened this issue Aug 21, 2017 · 12 comments

Comments

@quadsurf
Copy link

i have dozens of queries and mutations in my app, and they all work great, but the second i add the following query (a super basic query), i get the following error:

Unhandled (in react-apollo)
THIS IS NOT A NETWORK ERROR since all other queries still work!
This error is not too helpful and lacks any meaningful information to help me debug.

Please note that permissions aren't the issue, and the query below when tested in GraphiQL playground, works perfectly.

Also, to avoid github formatting, i changed the gql back ticks below from `` to ''

import { compose,graphql } from 'react-apollo'

const GetUserType = gql'
query GetUserType(
$UserId: ID
){
User(
id: $UserId
){
type
}
}'

export default compose(
graphql(GetUserType,{
name: 'getUserType',
options: props => ({
variables: {
UserId: props.user.id
},
fetchPolicy: 'network-only'
})
})
)(Colors)

LIB VERSIONS:
react-native@latest
react-apollo@1.4.8

@quadsurf
Copy link
Author

okay, problem solved... all i have to do is remove the fetchPolicy option, and it works again... this is not very consistent at all, especially since i am successfully using the fetchPolicy option in many other queries

even though it's resolved, i'm still hoping for an explanation here as to why fetchPolicy works great in some queries, but breaks the app in other, sometimes more basic, queries

@quadsurf
Copy link
Author

okay now i'm getting even more odd behavior... the query successfully and consecutively returns/fetches my data 3 times in a row, at an interval of 10 seconds apart (expected, since i'm using polling), but after the 3rd time, it crashes the app and returns the following error:

Possible Unhandled Promise Rejection (id: 0):
Error: Network error: Error writing result to store for query
query GetUserType(
$UserId: ID
){
User(
id: $UserId
){
type
}
}/nStore error: the application attempted to write an object with no provided id but the store already contains an id of User:***** for this object.

Any ideas?

@quadsurf
Copy link
Author

quadsurf commented Aug 21, 2017

okay, issue resolved... what triggers this mysterious error is returning/fetching a node's field value without including the id in the list of values to return in the response(see below)... apparently the id is needed in order to properly cache the response to the store... i don't remember seeing this any where in the docs, pls forgive if i overlooked this constraint

INCORRECT:
query GetUserType(
$UserId: ID
){
User(
id: $UserId
){
type
}
}

CORRECT:
query GetUserType(
$UserId: ID
){
User(
id: $UserId
){
id
type
}
}

@rkrueger11
Copy link

Thanks! Was having this issue as well.

@geirman
Copy link

geirman commented Jan 22, 2018

I had the same issue, and resolved with the same solution. Thanks!

@jthegedus
Copy link

For those having trouble reading the vertically aligned comparison above, here it is formatted:

# INCORRECT
query GetUserType($UserId: ID) {
  User(id: $UserId) {
    type
  }
}

# CORRECT
query GetUserType($UserId: ID) {
  User(id: $UserId) {
    id
    type
  }
}

Also, if your backend doesn't return an id field you can alias a unique value as the id on the client:

# ALIASING!
query GetUserType($UserId: ID) {
  User(id: $UserId) {
    id: username
    type
  }
}

@Laete
Copy link

Laete commented Jul 12, 2018

Thanks! Same issue got me :-)

@itumoraes
Copy link

Thanks @quadsurf! This worked for me!

@njbrake
Copy link

njbrake commented Feb 3, 2019

Thank you @quadsurf! I spent the past hour searching for the solution to this :)

@barbalex
Copy link

barbalex commented Apr 8, 2019

This has suddenly turned up in a project of mine with literally thousands of queries distributed over hundreds of components. I have been spending hours searching for a missing id but have not been able to resolve the problem yet :-(

iqqmuT added a commit to City-of-Helsinki/cnh-ui that referenced this issue Jan 16, 2020
@nathsimpson
Copy link

I was experiencing this issue today, and a colleague of mine helped me fix it.
In my case, the query looked something like this...

account {
   id
   company {
      name
   }
}

I looked around for any of my account queries that had a missing ID, but there were none. Turns out I had to also add an ID to my company item too, in order for Apollo to correctly cache it.

account {
   id
   company {
      id
      name
   }
}

Doing that solved my problem :D

@markhalonen
Copy link

This issue has burned me several times. The worst part is that I don't even want a cache, I've done everything in my power to disable the cache.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants